<?php
Class RedisServer{

    static public $redis = null;

    const REDIS_KEY_SEO = 'site_seo_data';
    const REDIS_KEY_NEWS_READ_COUNT = 'news_read_count';
    const REDIS_KEY_PAGE_COUNT = 'page_count:';
    const REDIS_KEY_SITE_MAPS = 'site_maps:';

    const REDIS_KEY_MAIN_INDEX_CACHE_DATA = 'main_index_cache_data:';//首页数据缓存

    static function init(){
        $dir_config = dirname(dirname(__FILE__)).'/Config/';
        $production = Configure::read('sgwy_production');
        $dir_config .= 'redis_'.$production.'.php';
        if(!empty(self::$redis)){
            return;
        }
        if(file_exists($dir_config)){
            require_once($dir_config);
            $conf = REDIS_CONFIG::$SERVERS;
            $redis = new Redis();
            $redis->connect($conf['host'], $conf['port']);
            if(!empty($conf['auth'])){
                $redis->auth($conf['auth']);
            }
            self::$redis = $redis;
        }else{
            throw new Exception("NO REDIS CONFIG !!");
        }
    }

    static function getArr($key){
        $data = self::$redis->get($key);
        if(!empty($data)){
            return json_decode($data, true);
        }
        return array();
    }
}
